#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>


//线程入口函数1
void * Pthread_Entry_1(void * arg)
{
  (void)arg;
  //printf("thread_1 running\n");
  pthread_detach(pthread_self());
  printf("%s\n",(char *)arg);
  return NULL;
}

//线程入口函数2
void * Pthread_Entry_2(void * arg)
{
  (void)arg;
  printf("thread_2 running\n");
  return NULL;
}

void test()
{
  //创建两个线程
  pthread_t thread_1,thread_2;
  pthread_create(&thread_1,NULL,Pthread_Entry_1,(void *)"thread_1 running");
  pthread_create(&thread_2,NULL,Pthread_Entry_2,NULL);

  sleep(1);

 //进行线程分离
 // pthread_detach(thread_1);
 // pthread_detach(thread_2);

  //进行线程等到
  int ret=pthread_join(thread_1,NULL);
  if(ret==0)
  {
    printf("wait success\n");
  }
  else
  {
    printf("wait failed\n");
  }
  pthread_join(thread_2,NULL);

}

int main()
{
  test();
  return 0;
}
